﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using chatGUI.Model;
using HandyControl.Controls;
using System.Diagnostics;

namespace chatGUI.UserControls
{
    /// <summary>
    /// chatAndDetailsControl.xaml 的交互逻辑
    /// </summary>
    public partial class chatAndDetailsControl : UserControl
    {
        public chatAndDetailsControl()
        {
            InitializeComponent();
        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var obj = sender as Image;
            new HandyControl.Controls.ImageBrowser(new Uri(obj.Source.ToString())).Show();
        }

        private void fileBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var obj = sender as Border;
            var grid = obj.Child as Grid;
            var data = grid.DataContext as chatBubbleModel;
            if (data.Message.ToString() == null)
                return;
            ProcessStartInfo processStartInfo = new ProcessStartInfo(data.Message.ToString());
            Process process = new Process();
            process.StartInfo = processStartInfo;
            process.StartInfo.UseShellExecute = true;
            process.Start();
        }
    }
    public class bubbleSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var contain = container as FrameworkElement;
            var obj = item as chatBubbleModel;
            switch (obj.ChatBubbleType)
            {
                case chatBubbleType.text:
                    return contain.FindResource("textBubble") as DataTemplate;
                case chatBubbleType.gif:
                    return contain.FindResource("gifBubble") as DataTemplate;
                case chatBubbleType.picture:
                    return contain.FindResource("pictureBubble") as DataTemplate;
                case chatBubbleType.file:
                    return contain.FindResource("fileBubble") as DataTemplate;
                default:
                    return contain.FindResource("textBubble") as DataTemplate;
            }
        }
    }
}
